package org.example.flink.windows;

import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.windowing.assigners.SlidingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;

public class Hello01Time {
    public static void main(String[] args) {
        StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();


        //设置 EventTime 作为时间标准
        environment.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
        //设置 IngestionTime 作为时间标准
        environment.setStreamTimeCharacteristic(TimeCharacteristic.IngestionTime);
        //设置 ProcessingTime 作为时间标准
        environment.setStreamTimeCharacteristic(TimeCharacteristic.ProcessingTime);

        DataStreamSource<String> source = environment.fromElements("a", "aa", "aaa", "b", "bb", "bbb");

        //1.12 及以后，flink 以 event time 作为默认的时间语义
        source.keyBy(w -> w)
                .window(SlidingEventTimeWindows.of(Time.seconds(10), Time.seconds(5)));
    }
}
